@extends('admin.main')

@section('body')
    <!-- 标题栏 -->
    <div class="main-title">
        <h2>商品列表</h2>
    </div>
    <div class="cf">
        <div class="fl">
            <button class="btn list_sort" url="{{urlAdmin('waterBill','getSort',['shop_id'=>request('shop_id')])}}">排序
            </button>
        </div>
        <!-- 高级搜索 -->
        <div class="search-form fr cf">
            <div class="sleft">
                <div class="drop-down" style="width: 200px;">
                    <span id="sch-sort-txt" class="sort-txt" style="width: 170px;" data="{{request('shop_id')}}">@if(!request('shop_id'))
                            全部 @else{{$curentShop['shop_name']}}@endif</span>
                    <i class="arrow arrow-down"></i>
                    <ul id="sub-sch-menu" class="nav-list hidden">
                        @if(count($shopList))
                            @foreach($shopList as $v)
                                <li><a href="javascript:;" style="width: 170px;"
                                       value="{{$v['id']}}">{{$v['shop_name']}}</a></li>
                            @endforeach
                        @endif
                    </ul>
                </div>
                <input type="text" name="keyword" class="search-input" value="{{request('keyword')}}"
                       placeholder="请输入商品名称">
                <a class="sch-btn" href="javascript:;" id="search" url="{{urlAdmin('waterBill','getIndex')}}"><i
                            class="btn-search"></i></a>
            </div>
        </div>
    </div>
    <!-- 数据列表 -->
    <div class="data-table table-striped">
        <table class="">
            <thead>
            <tr>
                <th class="row-selected row-selected"><input class="check-all" type="checkbox"/></th>
                {{--<th class="">ID</th>--}}
                <th class="">商品图片</th>
                <th class="">商品名称</th>
                <th class="">商品价格</th>
                <th class="">商品库存</th>
                <th class="">操作</th>
            </tr>
            </thead>
            <tbody>
            @if(count($rows['data']))
                @foreach($rows['data'] as $v)
                    @if($v['status'] > 0 || $v['water_bill'])
                        <tr>
                            <td><input class="ids" type="checkbox" name="ids[]" value="{{$v['id']}}"/></td>
                            {{--<td>{{$v['id']}}</td>--}}
                            <td>
                                <img src="/uploads/goods/imgs/{{$v['admin_id']}}/{{$v['goods_id']}}_1_{{$mini}}.{{$ext}}?{{time()}}"/>
                            </td>
                            <td>{{$v['goods_name']}}</td>
                            <td>{{$v['goods_price']}}</td>
                            <td>{{$v['goods_num']}}</td>
                            <td>
                                @if($v['water_bill'])
                                    <a href="javascript:;" onclick="showInfo({{$v['goods_id']}})">查看</a>
                                    <a title="编辑"
                                       href="{{urlAdmin('waterBill','getEdit',['id'=>$v['id'],'shop_id'=>$v['shop_id']])}}">编辑</a>
                                    @if($v['water_bill']['status'] == 1)
                                        <a href="{{urlAdmin('waterBill','anyChangeStatus',['ids'=>$v['water_bill']['id'],'shop_id'=>$v['shop_id'],'method'=>'down'])}}"
                                           class="confirm ajax-get" style="color:red">下架</a>
                                    @elseif($v['water_bill']['status'] == 0)
                                        待审核
                                    @endif
                                @else
                                    <a href="{{urlAdmin('waterBill','getAdd',['shop_id'=>$v['shop_id'],'id'=>$v['id']])}}"
                                       style="color: red">添加水票</a>
                                @endif
                            </td>
                        </tr>
                    @endif
                @endforeach
            @else
                <td colspan="12" class="text-center"> aOh! 暂时还没有内容!</td>
            @endif
            </tbody>
        </table>
    </div>
    <div class="page">
        @if($rows['last_page']>1)
            <div>
                @if($rows['prev_page_url'])
                    <a class="prev" href="{{$rows['prev_page_url']}}&shop_id={{request('shop_id')}}">&lt;&lt;</a>
                @endif
                @if(count($rows['pageNoList']))
                    @foreach($rows['pageNoList'] as $v)
                        @if($rows['current_page'] == $v)
                            <span class="current">{{$v}}</span>
                        @else
                            <a class="num"
                               href="{{urlAdmin('waterBill','getShopIndex',['page'=>$v,'shop_id'=>request('shop_id')])}}">{{$v}}</a>
                        @endif
                    @endforeach
                @endif
                @if($rows['next_page_url'])
                    <a class="next" href="{{$rows['next_page_url']}}&shop_id={{request('shop_id')}}">&gt;&gt;</a>
                @endif
                <span class="rows">共 {{$rows['total']}} 条记录</span>
            </div>
        @endif
    </div>
@endsection

@section('script')

    <script type="text/javascript">

        function showInfo(id) {
            //iframe层
            layer.open({
                type: 2,
                title: '水票详情',
                scrollbar: false,
                area: ['500px', '400px'],
                fixed: false, //不固定
                content: '{{urlAdmin('waterBill','getInfo')}}?id=' + id + '&shop_id={{request('shop_id')}}'
            });
        }

        function addGood(shop_id) {
            if (!shop_id) {
                layer.tips('添加商品前，请先选择店铺', '#sch-sort-txt', {
                    tips: [1, 'orange'],
                    time: 4000
                });
            } else {
                window.location.href = '{{urlAdmin('waterBill','getAdd',['shop_id'=>request('shop_id')])}}'
            }
        }

        //搜索功能
        $("#search").click(function () {
            var url = $(this).attr('url');
            var shop_id = $("#sch-sort-txt").attr("data");
            var query = $('.search-form').find('input').serialize();
            query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g, '');
            query = query.replace(/^&/g, '');
            if (shop_id != '') {
                query = 'shop_id=' + shop_id + "&" + query;
            }
            if (url.indexOf('?') > 0) {
                url += '&' + query;
            } else {
                url += '?' + query;
            }
            window.location.href = url;
        });

        /* 状态搜索子菜单 */
        $(".search-form").find(".drop-down").hover(function () {
            $("#sub-sch-menu").removeClass("hidden");
        }, function () {
            $("#sub-sch-menu").addClass("hidden");
        });
        $("#sub-sch-menu li").find("a").each(function () {
            $(this).click(function () {
                var text = $(this).text();
                if (text == '全部') {
                    window.location.href = '{{urlAdmin('waterBill','getIndex')}}';
                    return;
                }
                $("#sch-sort-txt").text(text).attr("data", $(this).attr("value"));
                $("#sub-sch-menu").addClass("hidden");
                var shop_id = $(this).attr("value");
                window.location.href = '{{urlAdmin('waterBill','getShopIndex')}}?shop_id=' + shop_id;
            })
        });
        //点击排序
        $('.list_sort').click(function () {
            var url = $(this).attr('url');
            var ids = $('.ids:checked');
            var param = '';
            if (ids.length > 0) {
                var str = new Array();
                ids.each(function () {
                    str.push($(this).val());
                });
                param = str.join(',');
            }

            if (url != undefined && url != '') {
                window.location.href = url + '&ids=' + param;
            }
        });
    </script>
@endsection
